//
//  LTHomeViewController.swift
//  textweibo
//
//  Created by 李付涛 on 2017/3/16.
//  Copyright © 2017年 江苏岳创信息科技有限公司. All rights reserved.
//

import UIKit

private let cellID = "cellID"

class LTHomeViewController: LTBaseViewController {
    
    lazy var dataList = [String]()
    
    
    
    /// 加载数据
    override func loadData() {
        
        let dic = ["pageNo":"1","pageSize":"20"]
        let urlStr = "http://www.gou12333.com/dubbo-sshelp-app/information/infomationList.app"
        
        LTNetWorkManager.shared.requst(method: .GET, URLString: urlStr, parameters: dic) { (json, isSucess) in
            
            if isSucess {
                print(json ?? "")
            }
            
        }
        
//        LTNetWorkManager.shared.post("", parameters: dic, progress: nil, success: { (_, json) in
//            print(json ?? "")
//        }) { (_, Error) in
//            print(Error)
//        }
        
        
        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
           for i in 0..<20 {
            self.dataList.insert(i.description, at: 0)
        }
            
            self.refreshController?.endRefreshing()
            
            self.tableView?.reloadData()
        }
        
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        
    }
    
    
   @objc func pushVC()  {
        let vc = LTDemoViewController()
        
        
        navigationController?.pushViewController(vc, animated: false)
    }

}

// MARK: - 设置方法
extension LTHomeViewController{

    override func setupUI() {
        super.setupUI()

        naviItem.rightBarButtonItem = UIBarButtonItem(title: "下一页", action: #selector(pushVC), target: self)
      tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellID)

    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataList.count
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: cellID, for: indexPath)
        
        cell.textLabel?.text = dataList[indexPath.row]
        
        return cell
    }
    
    
}
